<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%
   String path = request.getContextPath();
   String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
	<head>
        <base href="<%=basePath%>"/>  
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<title>后勤管理平台</title>
		<link href="css/init.css" rel="stylesheet" type="text/css"/>
		<link href="css/login.css" rel="stylesheet" type="text/css"/>
		<script src="js/jquery.js" language="JavaScript" type="text/javascript"></script>
		<script src="js/cloud.js" language="JavaScript" type="text/javascript"></script>
		<script language="javascript">
		    if(self.location!=top.location) window.parent.location.href = 'login.jsp';  //父页面跳转
			$(function(){
			    $('.loginbox').css({'position':'absolute','left':($(window).width()-542)/2});
			    $(window).resize(function(){  
				   $('.loginbox').css({'position':'absolute','left':($(window).width()-542)/2});
			    }) 
                changecode();
			}); 
			$(document).keydown(function (event) {
			   if (event.keyCode == 13) {
				   $("#loginbtn").click();
			   }
			}); 
			//登录
			function login(){
			   $("#loginbtn").attr("class","loginbtning").val("登录中...");
			   $.ajax( {    
                   url:'admin/login?username='+$('#username').val()+'&password='+$('#password').val()+'&code='+$('#code').val(), //请求flow       
                   type:'post',         
                   success:function(data) {  
                       if(data=="Y" ){    
						   window.location='<%=basePath%>main.jsp';    
					   }else if(data=="C" ){    
						   $("#loginbtn").attr("class","loginbtn").val("登录");
						   alert('验证码错误！');       
					   }else{    
					       $("#loginbtn").attr("class","loginbtn").val("登录");
						   alert('账号或密码错误！');    
					   }    
					   if(data!="Y") changecode();  //刷新验证码
				   },    
				   error : function() {
					   $("#loginbtn").attr("class","loginbtn").val("登录");     
					   alert("异常！");    
				   }    
               }); 
			}
			function changecode(){
				$('#code').val('');
				document.getElementById('chuanxucode').src="admin/code?"+Math.random();
			}
		</script> 
	</head>
	<body style="background-color:#1c77ac; background-image:url(images/loginlight.png); background-repeat:no-repeat; background-position:center top; overflow:hidden;">
		<div id="mainBody">
		  <div id="cloud1" class="cloud"></div>
		  <div id="cloud2" class="cloud"></div>
		</div>
        <div class="logintop">    
			<div>欢迎登陆后勤管理平台</div>    
		</div>
		<div class="loginbody">
		   <div class="loginbox">
              <p>后勤管理平台</p>
			  <ul>
				<li><input id="username" type="text"/></li>
				<li><input id="password" type="password"/></li>
                <li><input id="code" type="text" class="input3"/><input id="chuanxucode" type="image" onclick="changecode()"></li>
				<li><input type="submit" id="loginbtn" class="loginbtn" value="登录"  onclick="login();"/></li>
			  </ul>


		   </div>
		</div>
	</body>
</html>